﻿using SCG.General;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TTEngine
{
    public abstract class PC : Actor
    {
        //constructor
        public PC()
            : base()
        {
            Alignment = "Good";

            //full 20 movement, no orders
            Movement = 20;
            Orders = OrderType.None;

            //natural attack
            AttackName = "punches";
            Damage = new DamageExpressionList("1z3=b");

            //mundane gear
            AddStartingGear("Torch", 100, 1, 2);
            int mundane = Globals.RandomIntFromTo(2, 4);
            while (mundane > 0)
            {
                MapObject gear = MapObjectFactory.GetLoot(0);
                AddGear(gear);
                mundane--;
            }
        }
        public void AddStartingGear(string objectName, int chance, int min, int max)
        {
            if (Globals.RandomIntFromTo(1, 100) <= chance)
            {
                MapObject mo = MapObjectFactory.GetMapObject(objectName);
                mo.Quantity = Globals.RandomIntFromTo(min, max);
                AddGear(mo);
            }
        }

        //hostility
        public override bool IsHostile(Actor actor)
        {
            if (actor.Alignment == "Neutral")
                return false;
            return actor.Alignment != "Good";
        }

        //display name
        public override string DisplayName
        {
            get
            {
                if (_name == "")
                {
                    if (_maleNames == null)
                    {
                        string s = Properties.Resources.MaleNames;
                        _maleNames = CreateConfluxer(s);
                        s = Properties.Resources.FemaleNames;
                        _femaleNames = CreateConfluxer(s);
                    }
                    if (Globals.Random.NextDouble() > 0.5)
                        _name = _maleNames.RandomName;
                    else
                        _name = _femaleNames.RandomName;
                }
                return _name;
            }
        }

        //display label
        public override string DisplayLabel
        {
            get
            {
                return DisplayName + " the " + ClassName;
            }
        }

        //class name
        public string ClassName { get; set; }

        //create a confluxer
        protected Confluxer CreateConfluxer(string s)
        {
            string[] lines = s.Split('\r', '\n');
            Confluxer c = new Confluxer(lines);
            return c;
        }
        
        //private members
        private string _name = "";
        private static Confluxer _maleNames = null;
        private static Confluxer _femaleNames = null;
    }
}
